<!-- 从业者-个人求职-已投简历 -->
<template>
  <view class="container">
    <!-- 顶部选项卡 -->
    <u-tabs :list="tabList" :current="currentTab" @change="changeTab"></u-tabs>
    
    <!-- 简历列表 -->
    <view v-if="resumeList.length > 0">
      <view v-for="(item, index) in filteredResumes" :key="index" class="resume-item">
        <view class="resume-header">
          <text class="user-name">{{ item.gwinfo.gwi_name }}</text>
        <view class="resume-footer">
					<!-- 是否查看 -->
				  <text v-if="item.tdb_state == 0 || item.tdb_state == 1" class="status" :class="{'unviewed': item.jg_isread === 0,
																		'viewed': item.jg_isread === 1,
																		'rejected': item.jg_isread === 2,
																		'interview': item.jg_isread === 3}">
																{{ item.jg_isread == 0 ? '未查看' : '已查看' }}</text>
					<!-- 不合适或邀请 -->
					<text v-else class="status" :class="{'unviewed': item.tdb_state === 0,
																		'viewed': item.tdb_state === 1,
																		'rejected': item.tdb_state === 2,
																		'interview': item.tdb_state === 3}">
																{{ item.tdb_state == 2 ? '不合适' : '已邀请面试' }}</text>		
        </view>
        </view>
        <view class="resume-info">
          <text>{{ item.jginfo.yyzz.yyzz_name }} | {{ item.gwinfo.gwi_offer}}</text>
        </view>
				<view class="resume-info">
				  <text>{{ item.gwinfo.gwi_workaddr }}{{item.gwinfo.gwi_addr}} </text>
				</view>
        <view class="resume-footer">
          <text class="time">投递时间：{{ tdTime[index] }}</text>
        </view>
      </view>
    </view>
    
    <!-- 空状态 -->
    <u-empty v-else mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png"></u-empty>
  </view>
</template>

<script>
import util from '@/utils/util.js'
export default {
  data() {
    return {
      currentTab: 0,
      tabList: [
        { name: '全部' },
        { name: '未查看' },
        { name: '已查看' }
      ],
      resumeList: [
        {
          position: '康养师',
					company:'公司名称',
					payroll: '6-8K',
					city:'福州-鼓楼区',
					deliveryTime: '2025-05-23',
          status: '未查看'
        },
        {
          position: '康养师',
					company:'公司名称',
					payroll: '6-8K',
					city:'福州-鼓楼区',
					deliveryTime: '2025-05-23',
          status: '未查看'
        },
        {
          position: '康养师',
					company:'公司名称',
					payroll: '6-8K',
					city:'福州-鼓楼区',
					deliveryTime: '2025-05-23',
          status: '已邀面试'
        },
        {
          position: '康养师',
					company:'公司名称',
					payroll: '6-8K',
					city:'福州-鼓楼区',
					deliveryTime: '2025-05-23',
          status: '不合适'
        }
      ],
			gwData:[],
			tdTime:[], // 投递时间
    }
  },
	onShow() {
		this.$u.api.querytdjl({
			usercode: uni.getStorageSync('usercode'),
		}).then(res => {
			console.log('从业者已投岗位',res)
			this.gwData = res.data.base_info	
			// 转换投递时间
			for (var i=0; i< this.gwData.length; i++) {
				// 投递时间
				let tmpTime = util.formatDate(this.gwData[i].gwinfo.create_time)
				this.tdTime.push(tmpTime)		
			}
		})
		
	},
  computed: {
    filteredResumes() {
      if (this.currentTab === 0) return this.gwData
      if (this.currentTab === 1) return this.gwData.filter(item => item.jg_isread === 0 && item.tdb_state == 0)
      if (this.currentTab === 2) return this.gwData.filter(item => item.jg_isread === 1 || item.tdb_state === 2 || item.tdb_state === 3)
      return this.resumeList
    }
  },
  methods: {
    changeTab(index) {
      this.currentTab = index
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  padding: 20rpx;
}

.resume-item {
  padding: 30rpx;
  margin-bottom: 20rpx;
  background-color: #fff;
  border-radius: 10rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}

.resume-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15rpx;
  
  .user-name {
    font-size: 32rpx;
    font-weight: bold;
  }
  
  .position {
    font-size: 28rpx;
    color: #666;
  }
}

.resume-info {
  font-size: 26rpx;
  color: #888;
  margin-bottom: 20rpx;
}

.resume-footer {
  display: flex;
  justify-content: space-between;
  font-size: 24rpx;
  color: #999;
  
  .status {
    &.unviewed {
      color: #f56c6c;
    }
    &.viewed {
      color: #409eff;
    }
    &.interview {
      color: #67c23a;
    }
    &.rejected {
      color: #909399;
    }
  }
}
</style>